/*PSYZKs9kh2Fn61i59o3mRW4TyFGjTwJrRus2foPjyfZOBvTGHJpARYsW4pw30CM5*/



let dealCardData = (that, cardData) => {
    let newCardData = JSON.parse(JSON.stringify(cardData));
    let head = newCardData.head[that.formId].rows[0];
    let bodys = newCardData.body[that.tableId].rows;
    dealHead(head);
    dealbodys(bodys);

    //排序
    sortRowno(bodys);

    return newCardData;

}
let delCardDataForVailData = (that, cardData) => {
    let newCardData = JSON.parse(JSON.stringify(cardData));
    let head = newCardData.head[that.formId].rows[0];
    let bodys = newCardData.body[that.tableId].rows;

    newCardData.body[that.tableId].rows = dealbodysForVailData(bodys);

    return newCardData;
}

let dealHead = (head) => {
    let values = head.values;
    Object.keys(values).map((key, index) => {
        //清空value和display
        let value = values[key].value;
        let display = values[key].display;
        let scale = values[key].scale;
        // if((!value || value == '') && (!display || display =='') && scale == '-1'){
        //     delete values[key];
        // }
        if (value === null || value === undefined || value === '') {
            delete values[key];
        } else {
            values[key] = { value: value, scale: scale };
        }
        return null;
    });
}

let dealbodys = (bodys) => {
    let length = bodys.length;
    for (let i = 0; i < length; i++) {
        let body = bodys[i];
        let values = body.values;
        Object.keys(values).map((key) => {
            //清空value和display
            let value = values[key].value;
            let display = values[key].display;
            let scale = values[key].scale;
            // if((!value || value == '') && (!display || display =='') && scale == '-1'){
            //     delete values[key];
            // }
            if (value === null || value === undefined || value === '') {
                delete values[key];
            } else {
                values[key] = { value: value, scale: scale };
            }
            return null;
        });
    }
}
function dealbodysForVailData (bodys){
    let length = bodys.length;
    let retbody = [];
    for (let i = 0; i < length; i++) {
        let body = bodys[i];
        if (!(body && body.status && body.status == '3')) {
            retbody.push(body);
        } 
    }
    return retbody;
}
let sortRowno = (bodys) => {
    let length = bodys.length;
    for (let i = 0; i < length; i++) {
        let body = bodys[i];
        let rowno = i.toString();
        if (body.values.rowno) {
            body.values.rowno.value = rowno
        } else {
            body.values.rowno = { value: rowno };
        }

    }
}

export { dealCardData, delCardDataForVailData };
/*PSYZKs9kh2Fn61i59o3mRW4TyFGjTwJrRus2foPjyfZOBvTGHJpARYsW4pw30CM5*/